
/* start /web-platform/scripts/web-platform/shop.core.js*/
SOE.Shop=function(config){this.config=config;this.config.sort=this.config.sort||'origPrice';this.products=[];if(!this.config.ajaxUrl){throw'Make sure `ajaxUrl` is set to a valid URAM URL when you instantiate the page.';}else if(!this.config.container){throw'Make sure `container` is set to a valid ID, or array of IDs when you instantiate the page.';}else if(!this.config.template){throw'Make sure `template` is set to a valid ID, array of IDs, or Underscore template function when you instantiate the page.';}};SOE.Shop.prototype.init=function(){SOE.Shop.currency=wpCookie('shop-currency')||'USD';this.symbolMap={USD:{symbol:'\u0024',method:'currencyFront'},AUD:{symbol:'A\u0024',method:'currencyFront'},DKK:{symbol:'kr',method:'currencyBack'},EUR:{symbol:'\u20AC',method:'currencyFront'},GBP:{symbol:'\u00A3',method:'currencyFront'},NOK:{symbol:'kr',method:'currencyBack'},SEK:{symbol:'kr',method:'currencyBack'},CHF:{symbol:'Fr',method:'currencyBack'},JPY:{symbol:'\u00A5',method:'currencyFront'},BRL:{symbol:'R\u0024',method:'currencyFront'},SOE:{symbol:'',method:'currencyFront'}};if($('.currency.dropdown').length){this.setCurrency();}
this.loadUramData();};SOE.Shop.prototype.getUramData=function(){$.ajax({url:globs.urls.uramAjaxUrl+this.config.ajaxUrl+SOE.Shop.currency,dataType:'json',context:this,success:function(uramData){this.formatUramData(uramData[this.config.objName]);}});};SOE.Shop.prototype.shopAjax=function(url){var _this=this;return $.ajax({url:url,dataType:'json',context:_this}).done(function(result,signature){return(signature==='success')?result:{error:'shop request failed'};})};SOE.Shop.prototype.loadUramData=function(){var _this=this;var result=0;var signature=1;var requests=[];if(SOE.Shop.currency!=='USD'){requests=[_this.shopAjax(globs.urls.uramAjaxUrl+_this.config.ajaxUrl.replace(/locale=[a-zA-Z_]{5}/,'locale=en_US')+'USD'),_this.shopAjax(globs.urls.uramAjaxUrl+_this.config.ajaxUrl+SOE.Shop.currency)];}else{requests=[_this.shopAjax(globs.urls.uramAjaxUrl+_this.config.ajaxUrl+SOE.Shop.currency)];}
$.when.apply($,requests).then(function(usdReq,usersCurrencyReq){if(typeof usersCurrencyReq!=='undefined'&&Array.isArray(usersCurrencyReq)){if(usdReq[signature]==='success'&&usersCurrencyReq[signature]==='success'){if(_this.config.objName==='products'){for(var item in usersCurrencyReq[result][_this.config.objName]){if(usdReq[result].errors.length===0){usersCurrencyReq[result][_this.config.objName][item]['productoptions'][0].usDollarAmount=usdReq[result][_this.config.objName][item]['productoptions'][0].price.split('.')[0].replace(/[^0-9]+/g,'');}else{usersCurrencyReq[result][_this.config.objName][item]['productoptions'][0].usDollarAmount=0;}}}
if(_this.config.objName==='stationcashproducts'){for(var index in usersCurrencyReq[result][_this.config.objName]){if(usdReq[result].errors.length===0){usersCurrencyReq[result][_this.config.objName][index].usDollarAmount=usdReq[result][_this.config.objName][index].price.formattedPrice.split('.')[0].replace(/[^0-9]+/g,'');}else{usersCurrencyReq[result][_this.config.objName][index].usDollarAmount=0;}}}
_this.formatUramData(usersCurrencyReq[result][_this.config.objName]);}}else{if(usdReq){if(_this.config.objName==='products'){for(var item in usdReq[_this.config.objName]){usdReq[_this.config.objName][item]['productoptions'][0].usDollarAmount=usdReq[_this.config.objName][item]['productoptions'][0].price.split('.')[0].replace(/[^0-9]+/g,'');}}
if(_this.config.objName==='stationcashproducts'){for(var index in usdReq[_this.config.objName]){usdReq[_this.config.objName][index].usDollarAmount=usdReq[_this.config.objName][index].price.formattedPrice.split('.')[0].replace(/[^0-9]+/g,'');}}
_this.formatUramData(usdReq[_this.config.objName]);}}},function(err){console.log('ERROR',err);})}
SOE.Shop.prototype.getNumber=function(num){return num.replace(/[^\d\.]+/g,'');};SOE.Shop.prototype.setCurrency=function(){var _this=this;$('.currency.dropdown').on('click','a',function(evt){SOE.Shop.currency=evt.target.dataset.currency;_this.loadUramData();$('#currency-text, .currency.dropdown .currency-text').html(currencyMap[SOE.Shop.currency]);if(SOE.Shop.currency!=='SOE'){wpCookie('shop-currency',SOE.Shop.currency,30);}});$('#currency-text, .currency.dropdown .currency-text').html(currencyMap[SOE.Shop.currency]);};SOE.Shop.prototype.currencyFront=function(price){var renderedCurrency=(globs.soelocale==='en_US')?this.symbolMap[SOE.Shop.currency].symbol+price.replace(/^\D+/g,'').replace(/\D+$/g,''):price;return renderedCurrency;};SOE.Shop.prototype.currencyBack=function(price){var renderedCurrency=(globs.soelocale==='en_US')?price.replace(/^\D+/g,'').replace(/\D+$/g,'')+this.symbolMap[SOE.Shop.currency].symbol:price;return renderedCurrency;};SOE.Shop.prototype.sortProducts=function(){var that=this;if(this.config.sort&&typeof this.config.sort==='function'){this.products.sort(this.config.sort);}else if(this.config.sort&&typeof this.config.sort!=='object'){this.products.sort(function(a,b){return that.getNumber(a[that.config.sort])-that.getNumber(b[that.config.sort]);});}else{this.products.sort(function(a,b){return that.config.sort.sortArray.indexOf(a[that.config.sort.sortProperty])-that.config.sort.sortArray.indexOf(b[that.config.sort.sortProperty]);});}};SOE.Shop.prototype.formatUramData=function(uramProducts){var counter=0;for(var k=0;k<uramProducts.length;k++){var currProduct=uramProducts[k];if((!this.config.blacklist||!_.contains(this.config.blacklist.list,currProduct[this.config.blacklist.propertyName]))&&(!this.config.whitelist||_.contains(this.config.whitelist.list,currProduct[this.config.whitelist.propertyName]))){this.reMapProductData(counter++,currProduct);}}
this.sortProducts();this.renderProducts();this.products=[];};SOE.Shop.prototype.renderProducts=function(){var template;var container=this.config.container;if(Array.isArray(this.config.container)){for(var k=0;k<this.config.container.length;k++){if(Array.isArray(this.config.template)&&this.config.template.length==this.config.container.length){if(typeof this.config.template[k]==='function'){template=this.config.template[k]({products:this.products});}else{template=_.template($(this.config.template[k]).html(),{products:this.products});}}else{template=_.template($(this.config.template).html(),{products:this.products});}
$('.spinner').fadeOut();$(container[k]).html(template);}}else{if(Array.isArray(this.config.template)){for(var arr=0;arr<this.config.template.length;arr++){if(typeof this.config.template[arr]==='function'){template+=this.config.template[arr]({products:this.products});}else{template+=_.template($(this.config.template[arr]).html(),{products:this.products});}}}else if(typeof this.config.template==='function'){template=this.config.template({products:this.products});}else{template=_.template($(this.config.template).html(),{products:this.products});}
$('.spinner').fadeOut();$(container).html(template);}
if(this.config.callback){this.config.callback();}};

/* end /web-platform/scripts/web-platform/shop.core.js*/

/* start /web-platform/scripts/web-platform/helpers/responsive-image-modal.js*/
window.DGC=window.DGC||{};window.DGC.ResponsiveImageModal=function(options){'use strict';var _options=_.extend({linkSelector:undefined,modalSelector:undefined,imageSelector:undefined,closeSelector:undefined,closeButtonWidth:undefined,closeButtonHeight:undefined,closeButtonMargin:15,headerHeight:0,headerWidth:0},options);var imageWidth=undefined,imageHeight=undefined,imageAspect=undefined;function layoutThumbModal(){if(!imageAspect){return;}
var windowHeight=window.innerHeight;var windowWidth=window.innerWidth;var windowClearanceHorizontal=windowWidth-_options.headerWidth;var windowClearanceVertical=windowHeight-_options.headerHeight;var windowClearanceAspect=windowClearanceHorizontal/windowClearanceVertical;var imageScale;if(windowClearanceAspect>imageAspect){$(_options.imageSelector).addClass('constrain-height').removeClass('constrain-width');imageScale=Math.min(windowHeight/imageHeight,1);}else{$(_options.imageSelector).addClass('constrain-width').removeClass('constrain-height');imageScale=Math.min(windowWidth/imageWidth,1);}
var resultImageWidth=imageWidth*imageScale;var closeButtonClearanceHorizontal=(_options.closeButtonWidth+_options.closeButtonMargin)*2;var resultImageHeight=imageHeight*imageScale;var closeButtonClearanceVertical=(_options.closeButtonHeight+_options.closeButtonMargin)*2;$(_options.closeSelector).toggleClass('space-beside',windowWidth>=resultImageWidth+closeButtonClearanceHorizontal).toggleClass('space-above',windowHeight>=resultImageHeight+closeButtonClearanceVertical);}
var thumbModalUpdater=new DebouncedUpdater({callbacks:[layoutThumbModal],doInitialUpdate:false});$(window).on('resize',thumbModalUpdater.doUpdate.bind(thumbModalUpdater));$(_options.modalSelector).on('hidden.bs.modal',function(){imageWidth=imageHeight=imageAspect=undefined;});$(document).on('update.responsiveImageModal',function(e,href){var imageSizeTest=new Image();imageSizeTest.addEventListener('load',function(){imageWidth=this.width;imageHeight=this.height;imageAspect=imageWidth/imageHeight;$(_options.imageSelector).attr('src',href);thumbModalUpdater.doUpdate();});imageSizeTest.src=href;});$(document).on('click',_options.linkSelector,function(e){e.preventDefault();var largeImage=this.getAttribute('href');var imageSizeTest=new Image();imageSizeTest.addEventListener('load',function(){imageWidth=this.width;imageHeight=this.height;imageAspect=imageWidth/imageHeight;$(_options.imageSelector).attr('src',largeImage);thumbModalUpdater.doUpdate();$(_options.modalSelector).modal();});imageSizeTest.src=largeImage;});};

/* end /web-platform/scripts/web-platform/helpers/responsive-image-modal.js*/

/* start /scripts/_pages/expansions.js*/
$(document).ready(function(){'use strict';const expansionGroupEditionCardTemplate=_.template($('#expansionGroupEditionCardTemplate').html(),null,{variable:'data'});const expansionGroupTemplate=_.template($('#expansionGroupTemplate').html(),null,{variable:'data'});const featuresListTemplate=_.template($('#featuresListTemplate').html(),null,{variable:'data'});const productBoxTemplate=_.template($('#productBoxTemplate').html(),null,{variable:'data'});const previousExpansionTemplate=_.template($('#previousExpansionTemplate').html(),null,{variable:'data'});DGC.ResponsiveImageModal({linkSelector:'.screenshot-link',modalSelector:'#screenshotModal',imageSelector:'#screenshotModalImage',closeSelector:'#screenshotModalHeader',closeButtonWidth:0,closeButtonHeight:0,closeButtonMargin:0,headerHeight:35});function maxHeightOfSelection($selection){return Math.max.apply(null,$selection.map(function(i,el){const rect=el.getBoundingClientRect();return rect?rect.height:0;}).get());}
function equalizeHeights($selection){$selection.removeAttr('style');if(window.innerWidth>=768){$selection.css('minHeight',Math.ceil(maxHeightOfSelection($selection))+'px');}}
function matchEditionSizes(){$('.group-edition-cards').each(function(){equalizeHeights($('.group-edition-card-features-list',$(this)));});}
const editionSizer=new DebouncedUpdater({callbacks:[matchEditionSizes],doInitialUpdate:false});$(window).on('resize',editionSizer.doUpdate.bind(editionSizer));function toggleGroupHeroConstraints(){if(window.innerWidth>=768){const acctMenuHeight=$('.acct-links').height();const navMenuHeight=$('.floating-nav').height();const availableSpace=window.innerHeight-(acctMenuHeight+navMenuHeight);const widthScale=window.innerWidth/1400;$('.group-hero-desktop').each(function(i,el){const imgNativeHeight=parseInt(el.getAttribute('data-native-height'),10);const imgCurrentHeight=imgNativeHeight*widthScale;$(el).toggleClass('constrain-y',imgCurrentHeight>availableSpace);});}}
const heroSizer=new DebouncedUpdater({callbacks:[toggleGroupHeroConstraints],doInitialUpdate:false});$(window).on('resize',heroSizer.doUpdate.bind(heroSizer));function tagNativeImageSize(i,el){const img=el.getAttribute('src');const imageSizeTest=new Image();imageSizeTest.addEventListener('load',function(){el.setAttribute('data-native-width',this.width);el.setAttribute('data-native-height',this.height);heroSizer.doUpdate();});imageSizeTest.src=img;}
function isProductGroup(product){return Boolean(product.value.editions);}
function hasProduct(edition){return Boolean(edition.product);}
function hasAnyProducts(){return this.editions.filter(hasProduct).length>0;}
function preprocessExpansionGroup(){this.editionsWithProducts=this.editions.filter(hasProduct);if(this.subtypeArray&&Array.isArray(this.subtypeArray)&&this.subtypeArray.indexOf('upgradable')>=0){const editionsByPrice=this.editionsWithProducts.slice().sort(function(a,b){return SOE.Shop.prototype.getNumber(a.product.price)-SOE.Shop.prototype.getNumber(b.product.price);});if(editionsByPrice.length>1){this.editionsWithProducts.forEach(function(e){e.upgradable=Boolean(e.sku!==editionsByPrice[0].sku);});}}}
SSG.expansionGroups=SSG.productData.filter(isProductGroup).map(function(expansionGroup){return _.extend(expansionGroup,{value:_.extend(expansionGroup.value,{id:expansionGroup.value.name.toLowerCase().replace(/[^a-z]/g,'-').replace(/-{2,}/g,'-'),text:SSG.localizedText,ellipsis:SOE.Utils.ellipsisAtBreak,wrapDecimals:SSG.wrapDecimals,hasAnyProducts:hasAnyProducts,preprocess:preprocessExpansionGroup,hero:SSG.pickLocalized(expansionGroup.value.hero),editions:(expansionGroup.value.editions||[]).map(function(sku){const pieces=sku.value.split(':');return{id:pieces[0].trim(),sku:pieces[1].trim(),isHighlight:expansionGroup.value.highlight===pieces[0].trim(),cardTemplate:expansionGroupEditionCardTemplate};})})});});try{SSG.setCurrency();const shop=new SOE.Shop({ajaxUrl:'/rest/commerce/11/products.action?title='+globs.wdl.gameCode+'&filter=DLC&locale='+globs.soelocale+'&responseType=json&currency=',objName:'products',container:['#expansionGroupContents','#previousExpansionContents'],template:[expansionGroupTemplate,previousExpansionTemplate],sort:SSG.ordinalSort,callback:function(){editionSizer.doUpdate();$('.group-hero-desktop').each(tagNativeImageSize);DGC.EnableParallax();$('body').attr('data-currency',wpCookie('shop-currency')||'USD');if(window.location.hash&&window.location.hash.trim().length>0){window.setTimeout(DGC.ScrollTo.scrollTo.bind(DGC.ScrollTo,window.location.hash),250);}}});shop.reMapProductData=function(idx,product){if(!product.productoptions||product.productoptions.length<=0){return;}
const origPrice=this[this.symbolMap[SOE.Shop.currency].method](product.productoptions[0].originalPrice);const price=this[this.symbolMap[SOE.Shop.currency].method](product.productoptions[0].price);const discount=window.SSG.discountAmount(product.productoptions[0]);const baseProduct=lodash.merge({},product.productoptions[0],{origPrice:origPrice,price:price,discount:discount,isOnSale:product.productoptions[0].promotional===true&&typeof discount==='number'&&discount>0,purchaseUrl:'/goto?type=afterReg&targetUrlKey=dlcBuyDLCWithSkuAndMOPEntryPoint&theme='+globs.wdl.theme+'&locale='+globs.soelocale+'&currency='+SOE.Shop.currency+'&selectedSku='+product.productoptions[0].fullsku+'&service=',text:SSG.localizedText,ellipsis:SOE.Utils.ellipsisAtBreak,wrapDecimals:SSG.wrapDecimals});SSG.productData.filter(isProductGroup).forEach(function(group){group.value.editions.forEach(function(edition){if(edition.sku===baseProduct.fullsku){edition.product=baseProduct;}});});const prevExpansion=SSG.productData.filter(SSG.valueIsSku(baseProduct.fullsku));if(prevExpansion&&prevExpansion.length>0){const mergedProduct=lodash.merge({},baseProduct,prevExpansion[0].value,{ordinal:prevExpansion[0].ordinal,upgradable:prevExpansion[0].value.subtypeArray.indexOf('upgradable')>=0,thumbnail:window.SSG.pickLocalized(prevExpansion[0].value.thumbnails)||prevExpansion[0].value.thumbnail,featuresListTemplate:featuresListTemplate,productBoxTemplate:productBoxTemplate});this.products.push(mergedProduct);}};shop.init();}catch(error){console.error(error);}});

/* end /scripts/_pages/expansions.js*/
